package com.hlmc.spider;

import com.hlmc.dao.Zy2Dao;
import com.hlmc.entity.Zy2;
import com.hlmc.util.Atool;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.annotation.Resource;
import java.util.Map;

@Service("zy2_pipeline")
public class Zy2_pipeline implements Pipeline {

    @Resource
    private Zy2Dao zy2Dao;

    @Override
    public void process(ResultItems resultItems, Task task) {

        Map<String, Object> mapResults = resultItems.getAll();
        try {
            Zy2 dt = (Zy2) Atool.mapToObject(mapResults, Zy2.class);

            if (dt.getImage()!= null&&!dt.getImage().equals(" ")) {

                zy2Dao.AddZy2(dt);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}